Skip to content

Retain table and column comments in CREATE OR REPLACE TABLE#7035

Open
geraintcjy wants to merge 1 commit into
delta-io:masterfrom
geraintcjy:xta-16662-retain-comments-cort
Open

Retain table and column comments in CREATE OR REPLACE TABLE#7035
geraintcjy wants to merge 1 commit into
delta-io:masterfrom
geraintcjy:xta-16662-retain-comments-cort

Conversation

@geraintcjy

Copy link
Copy Markdown

Description

When a statement does not explicitly specify column or table comments, the existing comments from the table being replaced are now preserved.

Previously, replacing a table always discarded all comments, even when the replacement DDL made no mention of comments. This change introduces carry-over logic that matches column comments by case-insensitive name and recursively handles nested struct types.

A new configuration flag spark.databricks.delta.retainCommentsDuringReplace (default: true) gates this behavior for safe rollout. If a comment is explicitly specified in the new DDL (even an empty string), that value takes precedence.

Changes

  • Add comment carry-over logic to replaceMetadataIfNecessary() in CreateDeltaTableCommand
  • Introduce configuration flag retainCommentsDuringReplace in DeltaSQLConf
  • Column comments matched by case-insensitive name, recursively into nested structs
  • Explicit comment (including empty string) in new DDL always takes precedence

Tests

New and updated tests in DeltaTableCreationTests covering:

  • Column comment retention, explicit override, and explicit clear
  • Dropped/added columns, REPLACE TABLE AS SELECT, nested struct comments
  • Config-disabled fallback, table comment retention and override
  • Tests run across all three column mapping modes (NoMapping, NameMapping, IdMapping)

@geraintcjy geraintcjy force-pushed the xta-16662-retain-comments-cort branch from 85e9755 to d6033f3 Compare June 18, 2026 20:45
If enabled via a config flag, CREATE OR REPLACE TABLE now carries over table-level
and per-column comments from the previous table version when the replacement DDL
does not explicitly specify them.  The carry-over logic recurses into nested struct,
array, and map fields.
@geraintcjy geraintcjy force-pushed the xta-16662-retain-comments-cort branch from d6033f3 to a8610a4 Compare June 18, 2026 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant